<?php

use backend\widgets\ExportMenu;
use kartik\dynagrid\DynaGrid;

/* @var $this yii\web\View */
/* @var $searchModel */
/* @var $dataProvider yii\data\ActiveDataProvider */
/* @var $gridColumns */

$dynagridName   = 'dynagrid-' . $searchModel->formName();
$export_columns = $gridColumns;
foreach ($export_columns as $k => &$v) {
    if (isset($v['order'])) unset($v['order']);
}
$fullExportMenu = ExportMenu::widget([
    'minCount'        => 1000,
    'target'          => '_blank',
    'dataProvider'    => $dataProvider,
    'columns'         => $export_columns,
    'fontAwesome'     => true,
    'noExportColumns' => [0, 1],
    'linkPath'        => '/tmp',
    'folder'          => "@webroot/tmp",
    'filename'        => $dynagridName,
    'pjaxContainerId' => $dynagridName,
]);


$dynagrid = DynaGrid::begin([
    'options'             => [
        'id' => $dynagridName
    ],
    'showPersonalize'     => true,
    'columns'             => $gridColumns,
    'storage'             => 'db',
    'theme'               => 'panel-default',
//    'allowThemeSetting'=>false,
//    'allowFilterSetting'=>false,
//    'allowSortSetting'=>false,
    'deleteButtonOptions' => true,
    'gridOptions'         => [

//        'filterRowOptions'=>['class' => 'filters'],//搜索框的class
//        'headerRowOptions' => ['class'=>'abc'],//排序行的属性
//        'id' => 'idss',//设置table外的div的id
//        'options' => ['name' => 'options'],//设置table外的div的属性
//        'pager' => [//分页样式调整
//            'activePageCssClass'=>'active',
//            'options' => ['class' => 'pagination'],
//        ],
//        'showFooter' => false,//是否显示tfoot
//        'placeFooterAfterBody' => false,
//        'rowOptions' => ['name'=>'rowOptionsss'],//给每个tr加属性
//        'showHeader' => true,//是否显示表头(搜索行与th行)
//        'layout' => "{summary}\n{items}\n{pager}",//板块//layout有5个值，分别为{summary}、{errors}、{items}、{sorter}和{pager}。
//        'summary' => "{begin}-{end}-{count}-{totalCount}-{page}-{pageCount}",//数据的相关信息，行，页面，总数等
//        'summaryOptions' => ['class' => 'summarys'],
//        'afterRow' => function ()//每一行渲染后执行的方法
//        {
////             return '<td>111</td>';
//        },
//        'beforeRow' => function ()//每一行渲染前执行的方法
//        {
////             return '<td>222</td>';
//        },
//        'caption' => '表格的标题',//表格的标题
//        'captionOptions' => ['class'=>'capClass'],//表格的标题的html标签属性设置
//        'emptyCell' => '<p>null</p>',//单元格数据为空时显示的内容
//        'emptyText' => 'emptyText',//$dataProvider为空时显示的内容
        'perfectScrollbar'        => false,
        'perfectScrollbarOptions' => [
            'wheelPropagation' => true,
        ],
//        'afterRow' => function ()//每一行渲染后执行的方法
//        {
//             return '<td>111</td>';
//        },
        'floatHeader'             => true,
        'responsiveWrap'          => true,
        'dataProvider'            => $dataProvider,
        'filterModel'             => $searchModel,
        //'caption'=>"会员列表",
        'rowOptions'              => function ($model, $key, $index, $grid) use ($searchModel) {
            if ($key == 2) {
                return ['style' => 'color:red;'];
            }
        },
        'panelHeadingTemplate'    => '{heading}',
        'panelFooterTemplate'     => '<div class="clearfix"><div class="pull-left">{summary}</div><div class="pull-right">{pager}</div></div>',
        'showPageSummary'         => false,
        'pjax'                    => false,
        'panel'                   => [
            'heading' => false,
            'after'   => false
        ],
        'toolbar'                 => [
            [
                'content' => '<div  class="btn-group" role="group">{dynagridFilter}{dynagridSort}{dynagrid}' . $fullExportMenu . '</div>',
            ],
            [
                'content' => '<a class="fullscreen btn btn-default" href="javascript:void(0)" data-pjax="0"><i class="fa fa-expand"></i></a>',
            ],
        ]
    ]
]);
DynaGrid::end();